package com.zl.zlproject.base.fragment;

import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zl.zlproject.R;
import com.zl.zlproject.base.presenter.BaseContract;
import com.zl.zlproject.widget.ZlLayoutManager;


/**
 * Created by 郑磊 on 2018/6/17.
 */

public abstract class DefaultMvpFragment<P extends BaseContract.Presenter> extends BaseMvpFragment<P> implements OnRefreshListener {

    ViewStub mViewstubContainer;
    protected ZlLayoutManager mLayoutManager;

    protected SmartRefreshLayout mRefreshLayout;

    protected ImageView mIvBack;
    protected TextView mTvTitle;
    protected Toolbar mToolbar;
    protected LinearLayout mLlError;

    @Override
    protected int getContentLayoutId() {
        return R.layout.default_mvp;
    }

    @Override
    protected void initBefore() {
        mViewstubContainer = mRoot.findViewById(R.id.viewstub_container);
        mLayoutManager =mRoot.findViewById(R.id.layout_manager);
        mRefreshLayout =mRoot.findViewById(R.id.refresh_layout);
        mIvBack =mRoot.findViewById(R.id.iv_back);
        mTvTitle =mRoot.findViewById(R.id.tv_title);
        mToolbar =mRoot.findViewById(R.id.toolbar);
        mLlError =mRoot.findViewById(R.id.ll_error);

        mViewstubContainer.setLayoutResource(getContentRes());
        mRefreshLayout.setOnRefreshListener(this);
        mLayoutManager.showContent();
        mRefreshLayout.autoRefresh();
    }

    protected abstract int getContentRes();



    @Override
    public abstract void onRefresh(@NonNull RefreshLayout refreshLayout);

}
